package com.ph.irp.base.assistantmaterial.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.ph.exception.PHException;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantOpenaccountbankDAO;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantOpenaccountbankService;
import com.ph.irp.model.PBaseAssistantmaterialOpenaccountbank;

public class PBaseAssistantOpenaccountbankServiceImpl implements
		PBaseAssistantOpenaccountbankService {
	
	//出纳管理及开户行dao
	private PBaseAssistantOpenaccountbankDAO accountBankDAOProxy ;
	/**
	 * 新增出纳管理及开户行
	 */
	@Override
	public void addAccountBank(
			PBaseAssistantmaterialOpenaccountbank accountbookBankModel)
			throws Throwable {
		// TODO Auto-generated method stub
		try {
			accountBankDAOProxy.addAccountbookBank(accountbookBankModel) ;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new PHException("新增出纳管理及开户行出错，请重试！");
		}
	}
	/**
	 * 批量删除出纳管理及开户行
	 */
	@Override
	public void deleteAccountBankById(Object[] accountbookBankIds)
			throws Throwable {
		// TODO Auto-generated method stub
		try {
			accountBankDAOProxy.deleteAccountbookBankById(accountbookBankIds) ;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new PHException("删除出纳管理及开户行出错，请重试！");
		}
	}
	/**
	 * 动态查询出纳管理及开户行
	 */
	@Override
	public List<PBaseAssistantmaterialOpenaccountbank> getAllAccountBanks(PBaseAssistantmaterialOpenaccountbank accountbookBankModel)
			throws Throwable {
		// TODO Auto-generated method stub
		//出纳管理及开户行list
		List<PBaseAssistantmaterialOpenaccountbank> accountbankList = null ;
		
		//accountbookBankModel值为null，查询所有的出纳账号及开户行
		if(accountbookBankModel==null){
			try {
				accountbankList = accountBankDAOProxy.getAllAccountbookBanks();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else{
			//出纳管理及开户行name
			String name = accountbookBankModel.getOpenAccountBankName();
			//出纳账号及开户行code
			String code = accountbookBankModel.getOpenAccountBankCode() ;
			
			if(!name.equals("")&&!code.equals("")){//根据name和code动态查询出纳账号及开户行
				try {
					accountbankList = accountBankDAOProxy.getAccountbookBankByNameAndCode(name, code) ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			else if(!name.equals("")){////根据name动态查询出纳账号及开户行
				try {
					accountbankList = accountBankDAOProxy.getAccountbookBankByName(name) ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			else if(!code.equals("")){////根据code动态查询出纳账号及开户行
				try {
					accountbankList = accountBankDAOProxy.getAccountbookBankByCode(code) ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			else{
				try {
					accountbankList = accountBankDAOProxy.getAllAccountbookBanks() ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return accountbankList ;
	}
	/**
	 * 根据id查询出纳管理及开户行
	 */
	@Override
	public PBaseAssistantmaterialOpenaccountbank getAccountBankById(
			Integer accountbookBankId) throws Throwable {
		// TODO Auto-generated method stub
		//出纳管理及开户行model
		PBaseAssistantmaterialOpenaccountbank accountbankModel = null ;
		
		try {
			accountbankModel = accountBankDAOProxy.getAccountbookBankById(accountbookBankId) ;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new PHException("查询出纳管理及开户行出错，请重试！");
		}
		
		return accountbankModel;
	}
	/**
	 * 更新出纳管理及开户行
	 */
	@Override
	public void updateAccountBank(
			PBaseAssistantmaterialOpenaccountbank accountbookBankModel)
			throws Throwable {
		// TODO Auto-generated method stub
		
		try {
			accountBankDAOProxy.updateAccountbookBank(accountbookBankModel) ;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new PHException("更新出纳管理及开户行出错，请重试！");
		}

	}
	

	/**
	 * getters and setters for instance variables
	 * @return
	 */
	public PBaseAssistantOpenaccountbankDAO getAccountBankDAOProxy() {
		return accountBankDAOProxy;
	}
	public void setAccountBankDAOProxy(
			PBaseAssistantOpenaccountbankDAO accountBankDAOProxy) {
		this.accountBankDAOProxy = accountBankDAOProxy;
	}
	
	

	
}
